function addEvent(obj, evType, fn) {
    // http://www.scottandrew.com/weblog/articles/cbs-events
    if (obj.addEventListener){ 
        obj.addEventListener(evType, fn, false); 
        return true; 
    } else if (obj.attachEvent) { 
        var r = obj.attachEvent("on"+evType, fn); 
        return r; 
    } else { 
        return false; 
    } 
}
      
if(document.all && !document.getElementById) {
    document.getElementById = function(id) { return document.all[id]; }
}
      
function toggleVisibility(obj_id) {
    obj = document.getElementById(obj_id);
    if (typeof(obj) != null)
        obj.style.visibility = obj.style.visibility == "visible" ? "hidden" : "visible";
}
      
function navBar() {
    // I always forget that JavaScript is fun --ludo
        
    var nav = document.getElementById('nav');
    if (!nav || !nav.getElementsByTagName)
        return;
        
    var doc_href = document.location.href.toString();
        
    var nav_links = nav.getElementsByTagName('a');
    for (var i=0; i<nav_links.length; i++) {
        if (!nav_links[i].href)
            continue;
        var nav_link_href = nav_links[i].href.toString();
        if (nav_link_href == doc_href || nav_link_href == doc_href + '/')
            nav_links[i].className = 'selected';
    }
}
      
addEvent(window, "load", navBar);

function ReadCookie(name) {
    var cookie = "" + document.cookie;
    var i = cookie.indexOf(name);
    if (i==-1 || name=="")
        return; 
    var j = cookie.indexOf(';', i);
    if (j==-1)
        j = cookie.length; 
    return unescape(cookie.substring(i + name.length + 1, j));
}

function setCommentForm() {
    var lp_cookie = ReadCookie('lp_identity');
    if (!lp_cookie)
        return;
    var lp_identity = PHP_Unserialize(lp_cookie);
    if (!lp_identity)
        return;
    for (var k in lp_identity) {
        var el = document.getElementById(k);
        if (el)
            el.value = lp_identity[k];
    }
}

addEvent(window, "load", setCommentForm);
